from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import shutil
import os
import yaml
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains

from besins_selenium_downloaders import (
    BaseDownloaderChrome,
    BaseDownloaderFirefox,
    solve_captcha_image,
)


class Task51(BaseDownloaderFirefox):
    def login(self):
        pass

    def retrieve_data(self):
        pass

    def download_file(self):
        pass


self = Task51()
self.prepare_environment()
self.navigate_to_url()

self.driver.get("http://gys.yndzyf.com/")

# Fill in the first input field (tlxkh)
first_field = WebDriverWait(self.driver, 10).until(
    EC.visibility_of_element_located((By.ID, "tlxkh"))
)
first_field.clear()
first_field.send_keys("4505")

# Fill in the second input field (tusername)
second_field = WebDriverWait(self.driver, 10).until(
    EC.visibility_of_element_located((By.ID, "tusername"))
)
second_field.clear()
second_field.send_keys("abc")

# Fill in the third input field (tpass)
third_field = WebDriverWait(self.driver, 10).until(
    EC.visibility_of_element_located((By.ID, "tpass"))
)
third_field.clear()
third_field.send_keys("abc")

# Click the login verification button
login_verification_button = WebDriverWait(self.driver, 10).until(
    EC.element_to_be_clickable((By.ID, "yzm"))
)
login_verification_button.click()

# Wait a moment to see the result
time.sleep(2)

# Handle the slider verification

# Wait for the slider element to be visible
slider = WebDriverWait(self.driver, 10).until(
    EC.visibility_of_element_located((By.CLASS_NAME, "verify-move-block"))
)

# Create an ActionChains instance
action = ActionChains(self.driver)

# Perform the slider drag action (simulate sliding to the right)
# The slider is currently at left: 247px, so we need to drag it to the right
action.click_and_hold(slider).move_by_offset(150, 0).release().perform()

# Wait to see the result
time.sleep(3)
